<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
</head>
<body>
<jsp:include page="header.jsp" />
<script>setMenu(2);</script>
<div id="content" class="wrap">
	<div class="list bookList">
		<form method="post" name="shoping" action="order.do?opt=save">
			<table>
				<tr class="title">
					<th class="view">图片预览</th>
					<th>书名</th>
					<th class="nums">数量</th>
					<th class="price">价格</th>
				</tr>
				<c:forEach items="${sessionScope.car}" var="bk">
				<tr name="book">
					<td class="thumb"><img src="${bk.image}" /></td>
					<td class="title">${bk.bookname}</td>
					<td><input class="input-text nums" type="text"  
					onblur="calc();"
					name="nums" value="${bk.stock}" /></td>
					<td>￥<span class="price">${bk.b_price}</span></td>
				</tr>
				</c:forEach>				
				
			</table>
			<div class="button">
				<h4>总价：￥<span id="sum">65.00</span>元</h4>
				<input class="input-chart" type="submit" name="submit" value="" />
			</div>
		</form>
	</div>
</div>
<div id="footer" class="wrap">
	北大青鸟网上书城 &copy; 版权所有

</div>
<script>
	//计算
	function calc(){
		var trs=document.getElementsByName("book");
		var sum=0;
		for(var i=0;i<trs.length;i++){
			var tr=trs[i];
			var txt=tr.getElementsByClassName("nums")[0];
			var nums=txt.value;
			if(isNaN(nums)){//非数字
				nums=1;
				txt.value="1";
			}
			var price=tr.getElementsByClassName("price")[0].innerHTML;
			sum+=nums*price;
		}
		document.getElementById("sum").innerHTML=sum;
	}
	calc();
</script>
</body>
</html>
